<template>
  <div id="radio">
    <div class="type-title">
      <span style="color: #e10808">{{ index + 1 }}. {{ item.type }}</span>
    </div>
    <div class="title">
      <span v-for="(itm, idx) in splitTitle(item.title)" :key="idx">
        <input
          @blur="change"
          v-model="myAnswers[idx]"
          class="opt-input"
          v-if="itm == '＿' && !isdetail"
        />
        <span v-if="itm == '＿' && isdetail" class="detailK">
          {{ myAnswers[idx].split("&")[0] }}
          <span
            style="
              font-style: normal;
              color: #266fff;
              background-color: #e9effa;
              padding: 2px 6px 0 3px;
            "
            >{{ myAnswers[idx].split("&")[1] }}</span
          >
        </span>
        <span v-if="itm != '＿'">{{ itm }}</span>
        <!-- <span v-if="isdetail">{{ itm }} </span> -->
      </span>
      <span></span>
    </div>

    <div class="answer" v-if="isdetail">
      <div class="info">
        <i
          class="el-icon-success"
          v-if="item.enabledMark == 1"
          style="font-size: 30px; color: #1ec88b; float: left"
        ></i>
        <i
          class="el-icon-circle-close"
          v-else
          style="font-size: 30px; color: #ff4c50; float: left"
        ></i>
        <p>
          <span> {{ item.enabledMark == 1 ? "正确" : "错误" }}</span>
        </p>
        <!-- <p>
          <span>我的得分：</span>
          <span style="color: #266fff">{{ item.myScore }}</span>
        </p> -->
        <br />
        <div style="margin-left: 65px" v-if="item.answer">
          <span>答案解析 :</span>
          {{ item.answer }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "radio",
  props: {
    item: {
      type: Object,
    },
    index: {
      type: Number,
    },
    isdetail: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      myAnswers: {},
    };
  },
  mounted() {},
  methods: {
    change() {
      var myAnswersArr = [];
      for (let key in this.myAnswers) {
        if (this.myAnswers[key]) {
          myAnswersArr.push(this.myAnswers[key]);
        }
      }
      this.item.myAnswers = JSON.stringify(myAnswersArr);
      console.log("myAnswersArr", myAnswersArr);
      if (myAnswersArr.length != 0) {
        this.item.isAnswers = 1;
      } else {
        this.item.isAnswers = 0;
      }
      this.$emit("changeres", this.item, this.myAnswers);
    },
    splitTitle(txet) {
      var arr = txet.split("");
      var myAnswers = JSON.parse(this.item.myAnswers || "[]");
      var AnswersArr = JSON.parse(this.item.options);
      // var answerArr = arr.filter(el => {
      //     return el == '＿'
      // })
      // answerArr.forEach((el, idx) => {
      //     //  console.log(el)
      //     this.myAnswers[idx] = ''

      // });

      arr.forEach((el, idx) => {
        if (el == "＿") {
          this.myAnswers[idx] = "" + (myAnswers[0] ? myAnswers[0] : "");

          if (this.isdetail) {
            this.myAnswers[idx] += `&【 ${AnswersArr[0] || ""} 】`;
          }

          if (myAnswers.length != 0) {
            myAnswers.shift();
          }
          if (AnswersArr.length != 0) {
            AnswersArr.shift();
          }
        }
      });

      return arr;
    },
  },

  beforeDestroy() {},
};
</script>

<style lang="scss" scoped>
#radio {
  font-size: 16px;
  padding: 24px 24px 8px 24px;
  background-color: #fff;
  margin-bottom: 16px;

  .detailK {
    border-bottom: 1px solid #202020;
    padding: 1px 20px;
  }

  .title {
    width: 830px;
    overflow: hidden;

    // white-space: wrap;
    word-wrap: break-word;

    font-size: 18px;
    line-height: 1.7;
    color: #202020;
    margin: 16px 0;
  }

  .opt-input {
    margin-left: 10px;
    border: none;
    border-bottom: 1px solid #202020;
    padding: 1px 4px;
    text-align: center;
    width: 120px;
    outline: none;
  }

  //   .kong {
  //   }

  .opt-item {
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
    flex-direction: row;
    font-size: 16px;
    margin-bottom: 16px;
    line-height: 28px;
    cursor: pointer;

    .letter {
      width: 28px;
      height: 28px;
      border-radius: 50%;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: row;
      margin-right: 20px;
      border: 1px solid #ddd;
    }
  }

  .answer {
    background-color: #f9f9f9;
    padding: 22px 24px;
    display: flex;
    justify-content: space-between;
    align-items: unset;
    flex-direction: row;

    .info {
      width: calc(100% - 34px);
      font-size: 16px;
      line-height: 28px;
      color: #333;

      p {
        width: 160px;
        float: left;
        text-align: center;
      }
    }
  }
}
</style>
